package com.by.controller;

import com.alibaba.druid.stat.TableStat;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @author LittleDesire
 * @description
 * @date 2022-03-25 周五 17:29
 * @since 17
 */
@RestController
@SessionAttributes(value = {"admin","addr"}) // 将一个admin属性设置进session作用于当中
public class SessionController {

    @ModelAttribute
    public void admin(Model m) {
        // 为admin属性赋值
        m.addAttribute("admin", "root");
    }

    @RequestMapping("ss")
    public void s1(@SessionAttribute(name ="admin",required = false)String admin, Model m) {
        Object a = m.getAttribute("admin");
        System.out.println(a);
        System.out.println(admin);
        System.out.println(m.asMap());
    }
}
